
function urldecode (str) {
    // Decodes URL-encoded string
    //
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/urldecode
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +   improved by: Orlando
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +      bugfixed by: Rob
    // %        note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // %        note 2: Please be aware that this function expects to decode from UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    try{
        //return decodeURIComponent(str.replace(/\+/g, '%20'));
        str=str.replace('%92','%27');
        var s=unescape(str.replace(/\+/g, '%20'));
        return s;
    } catch(e){
    //alert("errore in "+str+" errore:"+dump(e));
        
    }
//return decodeURIComponent(str.replace("+", '%20'));
//while(str!=str.replace("+","%20"));
//return str;//unescape(str);
}
/**
 * Funzione che rimuove tutte le occorrenze di un elemento da un array
 * restituisce true se lo trova, false altrimenti
 * 
 */
function removeByElement(theArray,theElement)
{
    var reeter=false;
    for(var i in theArray){
        reeter=((theArray[i]==theElement)||reeter);
        if(reeter){
            theArray.splice(i,1);
            break;
        }
    }
    return reeter;
}

function arrayContains(theArray,theElement)
{
    var reeter=false;
    for(var i in theArray){
        reeter=((theArray[i]==theElement)||reeter);
        break;//storie se non funziona il break
    }
    //alert(reeter);
    return reeter;
}
/**
 * Funzione equivalente alla print_r in php
 */
function dump(arr,level) {
    var dumped_text = "";
    if(!level) level = 0;
    //The padding given at the beginning of the line.
    var level_padding = "";
    for(var j=0;j<level+1;j++) level_padding += "    ";

    if(typeof(arr) == 'object') { //Array/Hashes/Objects
        for(var item in arr) {
            var value = arr[item];

            if(typeof(value) == 'object') { //If it is an array,
                dumped_text += level_padding + "'" + item + "' ...\n";
                dumped_text += dump(value,level+1);
            } else {
                dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
            }
        }
    } else { //Stings/Chars/Numbers etc.
        dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
    }
    return dumped_text;
}
/**
 * Funzione di conversione del tempo di un evento in secondi. Il tempo dell'evento
 * può essere sia il tempo di inizio che quello di fine ed ha il formato
 * hh:mm:ss
 * restituisce la codifica in secondi della stringa che rappresenta gli
 * orari dell'evento
 */
function convertStringTimeToSeconds(timeString){
    try{
        var arr=timeString.split(":");
        //alert("ora: "+parseInt(arr[0],10)+":"+parseInt(arr[1],10)+":"+parseInt(arr[2],10)+"\n"+dump(arr)+" in secs:"+((parseInt(arr[0],10)*3600)+(parseInt(arr[1],10)*60)+parseInt(arr[2],10)));
        return (parseInt(arr[0],10)*3600)+(parseInt(arr[1],10)*60)+parseInt(arr[2],10);
    } catch(exn){
        alert(exn);
        return 0;
    }
}

/**
 * Funzione che permette di rimuovere il jsonp padding
 * Ora non fa ancora niente
 */
function removeJsonpPaddign(text){
    //return text;
    //return Ext.util.JSON.decode(text);
    //alert("TEXT "+text+" rob "+dump(jQuery.parseJSON(text)));
    //return $.parseJSON(text);
    return text;
}

/**
 * Permette di creare una richiesta json (o eventualmente jsonp), specifica la
 * callback a cui restituire l'oggetto json
 */
function jsonQuery(requestParams, backend, successFunction,failureFunction){
    try{
        //cambio i parametri per farli diventare una stringa get
        var retstring="";
        for(var p in requestParams){
            retstring+="&"+p+"="+requestParams[p];
        }
        jsonpBridgeV.jsonQuery(backend, retstring, successFunction);
    } catch(e){
        alert("Errore in jsonQuery() "+dump(e)+" \n<br/>"+dump(requestParams)+" \n<br/>"+dump(successFunction));
    }
}

function jsonQueryGetUrl(requestParams, backend, successFunction,failureFunction){
    var retstring="";
    for(var p in requestParams){
        retstring+="&"+p+"="+requestParams[p];
    }
    return backend+"&callback=jsonpBridgeV.cb&token="+"token"+retstring;
}

/**
 * Output del messaggio di errore, unificazione di ext message
 */
function printErrorMessage(title,text){
    Ext.Msg.alert(title, text);
}

//
//function jsonp_request(url,params,success) {
//    //alert(dump(requestParams));
//    var head = document.getElementsByTagName("head")[0];
//    var script = document.createElement("script");
//    script.type = "text/javascript";
//    //alert(success);
//    script.src = url+"&callback="+success;
//    head.appendChild(script);
////success();
//}



function stacktrace()
{
    re = /function\W+([\w-]+)/i;
    var f = arguments.callee;
    var s = "";
    while (f){
        s += (re.exec(f))[1] + '(';
        for (i = 0; i < f.arguments.length - 1; i++)        {
            s += "'" + f.arguments[i] + "', ";
        }
        if (arguments.length > 0)        {
            s += "'" + f.arguments[i] + "'";
        }
        s += ")\n\n";
        f = f.arguments.callee.caller;
    }
    return(s);
}

function LinkEvento(id){
    window.open('http://www.festivalscienza.it/site/fscienza/matchevent.jsp?id='+id,'Evento','width=800,height=600');
}

/**
 * Permette di ottenere l'identificativo dell'utente attualmente loggato
 */
function getUtente(){
    return 'mux';
}

function isUtenteFestival(utente){
    return(utente=='festival');
}

function isMuseum(evt, evtOrario){
    return convertStringTimeToSeconds(evtOrario.fine)-convertStringTimeToSeconds(evtOrario.inizio)>3600*2;
}